package com.edu.exam.enums;

/**
 * 批量操作项目类型枚举
 * 
 * @author S-01 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
public enum BatchItemType {
    QUESTION("QUESTION", "试题"),
    ATTACHMENT("ATTACHMENT", "附件"),
    VERSION("VERSION", "版本"),
    CATEGORY("CATEGORY", "分类"),
    TAG("TAG", "标签"),
    STATE("STATE", "状态"),
    PERMISSION("PERMISSION", "权限"),
    ATTRIBUTE("ATTRIBUTE", "属性");

    private final String code;
    private final String description;

    BatchItemType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static BatchItemType fromCode(String code) {
        for (BatchItemType type : BatchItemType.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown batch item type code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static BatchItemType fromDescription(String description) {
        for (BatchItemType type : BatchItemType.values()) {
            if (type.description.equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown batch item type description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}